package com.iman.Confucius.web.teacher;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.iman.Confucius.domain.MessageDetailBean;
import com.iman.Confucius.service.teacher.CareerPlanService;
import com.iman.Confucius.vo.teacher.CareerPalnVo;
import com.iman.Confucius.web.BaseController;

 
/**
 *  职业规划
 */
@Controller
@RequestMapping(value="/teacher/career/*")
public class CareerPlanController extends BaseController{
	@Autowired
	private CareerPlanService careerService;
 
	/**
	 * 
	 *  Function:
	 *  功能说明：  这样规划查询，  点击的时候  初始化页面查询，  先查下等待规划的
	 *	 使用说明：
	 *  @author  wangxiaolei  DateTime 2014年12月18日 上午12:01:51
	 *	返回类型: ModelAndView    
	 *  @param request
	 *  @return
	 */
	@RequestMapping(value="/init")
	public ModelAndView planning(HttpServletRequest request){	
		Map<String,Object> model = new HashMap<String,Object>();
		//model.put("user", "测试传递变量" );
		Long teacherid = this.getUserIdInSession(request);
		model.put("unplanList", this.careerService.unplanStudents(teacherid));
		ModelAndView view = new ModelAndView("teacher/teac_plan",model);
				
		//每个做后都要加上这个
		putResourceSrc(view);
		//点击tab颜色
		//view.addObject("tabstatus" , "2");

				
		return view;
	}
	
/******************************************************************************************************************************/
	
	 
	
	/**
	 * 
	 *  Function:
	 *  功能说明：  这样规划查询，    已经规划完成的
	 *	 使用说明：
	 *  @author  wangxiaolei  DateTime 2014年12月18日 上午12:01:51
	 *	返回类型: ModelAndView    
	 *  @param request
	 *  @return
	 */
	@RequestMapping(value="/planed")
	public ModelAndView planed(HttpServletRequest request){	
		Map model = new HashMap();
		//model.put("user", "测试传递变量" );
		Long teacherid = this.getUserIdInSession(request);
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("teacher_id",teacherid);
		
		List<Map> list  = this.careerService.planedStudents(params);
		for(Map studentMap : list){
			params.put("student_id", studentMap.get("student_id"));
			params.put("class_id", studentMap.get("class_id"));
			studentMap.put("plannings", this.careerService.planedStudentsPlanings(params));
		}
		model.put("plannedList", list);
		ModelAndView view = new ModelAndView("teacher/teac_planunmember",model);
		
		
		//每个做后都要加上这个
		putResourceSrc(  view);
		//点击tab颜色
		//view.addObject("tabstatus" , "2");
				
		return view;
	}
	/**
	 * 保存教师上传的职业规划
	 * @param classid
	 * @param studentid
	 * @param planName
	 * @param planid
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/save_career_plan")
	@ResponseBody
	public Map saveCareerPlan(@RequestParam long classid,@RequestParam long studentid,
			@RequestParam String planName,@RequestParam String planid,
			HttpServletRequest request) throws Exception{
		Map<String,Object> params = new HashMap<String,Object>();
		//System.out.println(new String(planName.getBytes("ISO-8859-1"),"utf8"));
		params.put("teacher_id", this.getUserIdInSession(request));
		params.put("student_id", studentid);
		params.put("class_id", classid);
		params.put("plan_name", new String(planName.getBytes("ISO-8859-1"),"utf8"));
		params.put("planning_id", planid);
		params.put("upload_dt", new Date());
		this.careerService.saveCareerPlan(params);
		Map<String,Object> result = new HashMap<String,Object>();
		result.put("success", true);
		return result;
	}
	/**
	 * 删除职业规划
	 * @param careerid
	 * @return
	 */
	@RequestMapping(value="/delete_carrer/{careerid}")
	@ResponseBody
	public Map deleteCareerPlan(@PathVariable long careerid){
		Map<String,Object> result = new HashMap<String,Object>();
		result.put("success", true);
		this.careerService.deleteCareerPlan(careerid);
		return result;
	}
	/**
	 * 记录职业规划下载次数
	 * @param careerid
	 * @return
	 */
	@RequestMapping(value="/download_carrer/{careerid}")
	@ResponseBody
	public Map downCarrerPlan(@PathVariable long careerid){
		Map<String,Object> result = new HashMap<String,Object>();
		result.put("success", true);
		this.careerService.downloadCarrer(careerid);
		return result;
	}
}
